home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / components / dhDumpProcessor.js < prev    next >
Text File  |  2010-01-15  |  6KB  |  169 lines

  1. /******************************************************************************
  2.  *            Copyright (c) 2006-2009 Michel Gutierrez. All Rights Reserved.
  3.  ******************************************************************************/
  4.  
  5. /**
  6.  * Constants.
  7.  */
  8.  
  9. const NS_DUMPPROC_CID = Components.ID("{c0b558fd-d32a-4b7f-ae48-5ef095134292}");
  10. const NS_DUMPPROC_PROG_ID = "@downloadhelper.net/dump-processor;1";
  11. const DHNS = "http://downloadhelper.net/1.0#";
  12.  
  13. var Util=null;
  14.  
  15. /**
  16. * Object constructor
  17. */
  18. function DumpProc() {
  19.     try {
  20.         //dump("[DumpProc] constructor\n");
  21.  
  22.         var prefService=Components.classes["@mozilla.org/preferences-service;1"]
  23.                                            .getService(Components.interfaces.nsIPrefService);
  24.         this.pref=prefService.getBranch("dwhelper.");
  25.         var dpe=false;
  26.         try {
  27.             dpe=this.pref.getBoolPref("dump-processor-enable");
  28.         } catch(e) {}
  29.         if(dpe) {
  30.             this.core=Components.classes["@downloadhelper.net/core;1"].
  31.                 getService(Components.interfaces.dhICore);
  32.             this.core.registerProcessor(this);
  33.         }
  34.     } catch(e) {
  35.         dump("[DumpProc] !!! constructor: "+e+"\n");
  36.     }
  37. }
  38.  
  39. DumpProc.prototype = {
  40.         get name() { return "dump"; },
  41.         get provider() { return "DownloadHelper"; },
  42.         get title() { return Util.getText("processor.dump.title"); },
  43.         get description() { return Util.getText("processor.dump.description"); },
  44.         get enabled() { return true; },
  45. }
  46.  
  47. DumpProc.prototype.canHandle=function(desc) {
  48.     //dump("[DumpProc] canHandle()\n");
  49.     return true;
  50. }
  51.  
  52. DumpProc.prototype.requireDownload=function(desc) {
  53.     //dump("[DumpProc] requireDownload()\n");
  54.     return false;
  55. }
  56.  
  57. DumpProc.prototype.preDownload=function(desc) {
  58.     //dump("[DumpProc] preDownload()\n");
  59.     return true;
  60. }
  61.  
  62. DumpProc.prototype.handle=function(desc) {
  63.     //dump("[DumpProc] handle()\n");
  64.     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  65.                                 .getService(Components.interfaces.nsIWindowMediator);
  66.     var w = wm.getMostRecentWindow("navigator:browser");
  67.     w.openDialog('chrome://dwhelper/content/dump-media.xul','_blank',"chrome,centerscreen",desc);
  68. }
  69.  
  70. DumpProc.prototype.QueryInterface = function(iid) {
  71.     //dump("[DumpProc] QueryInterface("+iid+")\n");
  72.     if(
  73.         iid.equals(Components.interfaces.dhIProcessor) ||
  74.         iid.equals(Components.interfaces.nsISupports)
  75.     ) {
  76.         return this;
  77.     }
  78.     throw Components.results.NS_ERROR_NO_INTERFACE;
  79. }
  80.  
  81. var vDumpProcModule = {
  82.     firstTime: true,
  83.     
  84.     /*
  85.      * RegisterSelf is called at registration time (component installation
  86.      * or the only-until-release startup autoregistration) and is responsible
  87.      * for notifying the component manager of all components implemented in
  88.      * this module.  The fileSpec, location and type parameters are mostly
  89.      * opaque, and should be passed on to the registerComponent call
  90.      * unmolested.
  91.      */
  92.     registerSelf: function (compMgr, fileSpec, location, type) {
  93.  
  94.         if (this.firstTime) {
  95.             this.firstTime = false;
  96.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  97.         }
  98.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  99.         compMgr.registerFactoryLocation(NS_DUMPPROC_CID,
  100.                                         "DumpProc",
  101.                                         NS_DUMPPROC_PROG_ID, 
  102.                                         fileSpec,
  103.                                         location,
  104.                                         type);
  105.     },
  106.  
  107.     unregisterSelf: function(compMgr, fileSpec, location) {
  108.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  109.         compMgr.unregisterFactoryLocation(NS_DH_DUMPPROC_CID, fileSpec);
  110.     },
  111.  
  112.     /*
  113.      * The GetClassObject method is responsible for producing Factory and
  114.      * SingletonFactory objects (the latter are specialized for services).
  115.      */
  116.     getClassObject: function (compMgr, cid, iid) {
  117.         if (!cid.equals(NS_DUMPPROC_CID)) {
  118.             throw Components.results.NS_ERROR_NO_INTERFACE;
  119.         }
  120.  
  121.         if (!iid.equals(Components.interfaces.nsIFactory)) {
  122.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  123.         }
  124.  
  125.         return this.vDumpProcFactory;
  126.     },
  127.  
  128.     /* factory object */
  129.     vDumpProcFactory: {
  130.         /*
  131.          * Construct an instance of the interface specified by iid, possibly
  132.          * aggregating it with the provided outer.  (If you don't know what
  133.          * aggregation is all about, you don't need to.  It reduces even the
  134.          * mightiest of XPCOM warriors to snivelling cowards.)
  135.          */
  136.         createInstance: function (outer, iid) {
  137.             if (outer != null) {
  138.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  139.             }
  140.     
  141.             if(Util==null) 
  142.                 Util=Components.classes["@downloadhelper.net/util-service;1"]
  143.                     .getService(Components.interfaces.dhIUtilService);
  144.  
  145.             return new DumpProc().QueryInterface(iid);
  146.         }
  147.     },
  148.  
  149.     /*
  150.      * The canUnload method signals that the component is about to be unloaded.
  151.      * C++ components can return false to indicate that they don't wish to be
  152.      * unloaded, but the return value from JS components' canUnload is ignored:
  153.      * mark-and-sweep will keep everything around until it's no longer in use,
  154.      * making unconditional ``unload'' safe.
  155.      *
  156.      * You still need to provide a (likely useless) canUnload method, though:
  157.      * it's part of the nsIModule interface contract, and the JS loader _will_
  158.      * call it.
  159.      */
  160.     canUnload: function(compMgr) {
  161.         return true;
  162.     }
  163. };
  164.  
  165. function NSGetModule(compMgr, fileSpec) {
  166.     return vDumpProcModule;
  167. }
  168.  
  169.